<template>
	<view class="register">
		<!-- 头像 -->
		<view class="header">
			<image class="img" :src="icon" @tap="uploadImg"></image>
		</view>
		<!-- 内容 -->
		<view class="main">
			<view class="item">
				<input class="ipt" type="number" v-model="phone" placeholder="手机号" />
			</view>
			<view class="item">
				<input class="ipt" type="number" v-model="password" placeholder="请输入登陆密码" :password="true" />
				<view class="icon" :class=" currentIcon ? 'icon1' : 'icon2' " @tap="passwordEvents"></view>
			</view>
			<view class="item">
				<input class="ipt" type="text" v-model="username" placeholder="请输入用户名 该用户名将用于账户登录" />
			</view>
			<view class="item">
				<input class="ipt" type="text" v-model="nickname" placeholder="请输入昵称" />
			</view>
			<view class="item">
				<input class="ipt" type="number" v-model="code" placeholder="请输入验证码" />
				<view class="text">获取验证码</view>
			</view>
		</view>
		<!-- 注册 -->
		<view class="btn" @tap="goRegister">
			注 册
		</view>
		<!-- 协议 -->
		<view class="footer">
			<view class="agree" :class=" currentAgree ? 'dot' : 'circle' " @tap="agreeEvents">同意</view>
			<view class="text">《协议》</view>
		</view>
	</view>
</template>

<script>
	import { register } from "../../../api/user/index.js";
	import baseUrl from "../../../api/baseUrl.js"
	export default {
		data() {
			return {
				// icon:'', // 传参 - 头像
				icon:'../../../static/icons/leju-logo.png', // 传参 - 头像
				phone:'17596496508', // 传参 - 手机号
				password:'123456', // 传参 - 密码
				username:'17596496508', // 传参 - 用户名
				nickname:'人间之神', // 传参 - 昵称
				code:'1234', // 注册 - 验证码
				currentAgree: false, // 注册 - 同意 + 不同意
				currentIcon: false, // 注册 - 同意 + 不同意
			};
		},
		methods:{
			// 同意 - 不同意
			agreeEvents(){
				this.currentAgree = !this.currentAgree
			},
			// 密码图标 - 切换
			passwordEvents(){
				this.currentIcon = !this.currentIcon
			},
			// 上传图片
			uploadImg(){
				var _this = this;
				uni.chooseImage({
					count:1,
					sizeType: ["original"],
					sourceType:["album"],
					success(res){
						uni.uploadFile({
							url: baseUrl + '/lejuClient/login/uploadAvatar',
							filePath: res.tempFilePaths[0],
							name: 'file',
							timeout: 5000,
							success(res1){
								_this.icon = JSON.parse(res1.data).data.fileUrl;
							}
						})
					}
				})
			},
			// 注册账号
			goRegister(){
				register({
				  "icon": this.icon,
				  "nickname": this.nickname,
				  "password": this.password,
				  "phone": this.phone,
				  "username": this.username,
				}).then(res=>{
					// 返回 - 上一页
					if(res.data.success){
						setTimeout(function(){
							uni.navigateBack()
						},1000)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
@import './index.scss'
</style>
